package com.ww.controller;

import com.ww.pojo.WallpaperPraise;
import com.ww.service.WallpaperPraiseService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * (WallpaperPraise)表控制层
 *
 * @author makejava
 * @since 2022-05-24 17:02:24
 */
@RestController
@RequestMapping("wallpaperPraise")
public class WallpaperPraiseController {
    /**
     * 服务对象
     */
    @Resource
    private WallpaperPraiseService wallpaperPraiseService;

    @RequestMapping("/checkpraise")
    public boolean checkprise(@RequestParam("wallpaperId") Integer wallpaperId,HttpSession httpSession){
        if (httpSession.getAttribute("userId")==null){
            return false;
        }else{
            WallpaperPraise wallpaperPraise= this.wallpaperPraiseService.checkpraise(Integer.parseInt(httpSession.getAttribute("userId").toString()),wallpaperId);
            return wallpaperPraise != null;
        }
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<WallpaperPraise> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.wallpaperPraiseService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param wallpaperPraise 实体
     * @return 新增结果
     */
    @RequestMapping("/praise")
    public ResponseEntity<WallpaperPraise> add(@RequestBody WallpaperPraise wallpaperPraise) {
        return ResponseEntity.ok(this.wallpaperPraiseService.insert(wallpaperPraise));
    }




    /**
     * 编辑数据
     *
     * @param wallpaperPraise 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<WallpaperPraise> edit(WallpaperPraise wallpaperPraise) {
        return ResponseEntity.ok(this.wallpaperPraiseService.update(wallpaperPraise));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.wallpaperPraiseService.deleteById(id));
    }

}

